package com.qi.demo01.Lock8;

import java.util.concurrent.TimeUnit;

/**
 * @author zjq
 * @date 2020/3/31 20:22
 */
public class TestSpinLockDemo {
    public static void main(String[] args) {
        SpinlockDemo spinlockDemo = new SpinlockDemo();

        new Thread(() -> {
            spinlockDemo.myLock();//加锁
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                spinlockDemo.myUnLock();//解锁
            }
        }, "t1").start();
        new Thread(() -> {
            spinlockDemo.myLock();//加锁
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                spinlockDemo.myUnLock();//解锁
            }
        }, "t2").start();


    }
}
